import tourList from '../src/data/tourist.json';
import serveList from '../src/data/serve.json';
import chatList from '../src/data/chat.json';
import peopleList from '../src/data/kefu.json';
import louList from '../src/data/fang_house.json';
import sandList from '../src/data/fang_house_sand.json';
import rentList from '../src/data/fang_rental.json';
import secondList from '../src/data/fang_second_house.json';
import officeSaleList from '../src/data/fang_office.json';
import officeRentList from '../src/data/fang_office_rental.json';
import shangRent from '../src/data/fang_shops_rental.json';
export default {
  // 获取游客列表
  'GET /getTourlist': tourList,
  // 获取服务记录
  'GET /getServelist': (req: any, res: any) => {
    //  判断有没有搜索值
    const { value } = req.query;
    console.log(req.query);

    if (value) {
      const arr = serveList.data.filter((item) => {
        return item.kefu_name.includes(value);
      });
      res.send(arr);
    } else {
      res.send(serveList);
    }
  },
  // 获取聊天记录
  'GET /getChatlist': (req: any, res: any) => {
    //  判断有没有搜索值
    const { value } = req.query;
    console.log(req.query);
    if (value) {
      const arr = chatList.data.filter((item) => {
        return item.from_name.includes(value);
      });
      res.send(arr);
    } else {
      res.send(chatList);
    }
  },

  // 获取客服列表
  'Get /getPeoplelist': (req: any, res: any) => {
    // console.log(req.query);
    // res.send(peopleList);
    const { value } = req.query;
    // console.log(peopleList.data);

    if (value) {
      const arr = peopleList.data.filter((item) => {
        return item.kefu_name.includes(value);
      });
      res.send(arr);
    } else {
      res.send(peopleList);
    }
  },

  // 获取楼盘数据
  'GET /getLouList': louList,

  // 获取编辑详情
  'GET /getDetailList': (req: any, res: any) => {
    const { id } = req.query;

    const arr = louList.data.find((item: any) => item.id == id);
    res.send(arr);
  },

  // 获取在线客服列表
  'GET /getOnlineList': (req: any, res: any) => {
    const arr: any = [];
    peopleList.data.map((item: any) => {
      if (item.connect_stauts === 1) {
        return arr.push(item);
      }
    });
    res.send(arr);
  },

  // 获取在线访客数
  'GET /getVistor': (req: any, res: any) => {
    const arr: any = [];
    tourList.data.map((item: any) => {
      if (item.online_status === 1) {
        return arr.push(item);
      }
    });
    res.send(arr);
  },

  // 删除接口
  'GET /dels': (req: any, res: any) => {
    const { id } = req.query;
    console.log(id);
    const arr = JSON.parse(JSON.stringify(louList.data));
    arr.forEach((item: any, index: number) => {
      if (item.id == id) {
        arr.splice(index, 1);
      }
    });
    res.send(arr);
  },

  // 获取沙盘列表
  'GET /sand': sandList,

  // 获取租房列表
  'GET /rent': rentList,
  // 获取二手房列表
  'GET /second': secondList,

  // 获取商铺写字楼出售管理
  'GET /getBuildSale': officeSaleList,

  // 获取商铺写字楼出租管理
  'GET /getBuildRent': officeRentList,

  // 获取商铺出租管理
  'GET /getShangRent': shangRent,

  // 获取商铺出售管理
  'GET /getShangSale': rentList,
};
